{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# GIT\n",
    "[Git 教程](https://www.runoob.com/git/git-tutorial.html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Initialized empty Git repository in D:/Desktop/NoteBooks/GIT/.git/\n"
     ]
    }
   ],
   "source": [
    "# 初始化 git \n",
    "! git init "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "On branch master\n",
      "\n",
      "No commits yet\n",
      "\n",
      "Untracked files:\n",
      "  (use \"git add <file>...\" to include in what will be committed)\n",
      "\n",
      "\t.ipynb_checkpoints/\n",
      "\tGIT.emmx\n",
      "\tGIT.ipynb\n",
      "\tREADME.md\n",
      "\n",
      "nothing added to commit but untracked files present (use \"git add\" to track)\n"
     ]
    }
   ],
   "source": [
    "# 查看 git 状态\n",
    "! git status "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 生成 gitignore 文件\n",
    "! touch .gitignore"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 新增 ignore 文件夹\n",
    "! echo .ipynb_checkpoints/ >> .gitignore"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 新增 ignore 文件\n",
    "! echo GIT.emmx >> .gitignore\n",
    "# 新增 ignore 文件\n",
    "! echo GIT.ipynb >> .gitignore"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ".ipynb_checkpoints/ \n",
      "GIT.emmx \n",
      "GIT.ipynb \n"
     ]
    }
   ],
   "source": [
    "# 查看  ignore 文件\n",
    "! cat .gitignore"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "On branch master\n",
      "\n",
      "No commits yet\n",
      "\n",
      "Untracked files:\n",
      "  (use \"git add <file>...\" to include in what will be committed)\n",
      "\n",
      "\t.gitignore\n",
      "\tREADME.md\n",
      "\n",
      "nothing added to commit but untracked files present (use \"git add\" to track)\n"
     ]
    }
   ],
   "source": [
    "# 查看 git 状态\n",
    "! git status "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将修改后文件加入仓库\n",
    "! git add README.md\n",
    "! git add ."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[master (root-commit) 1eff00e] 'add_01'\n",
      " 2 files changed, 40 insertions(+)\n",
      " create mode 100644 .gitignore\n",
      " create mode 100644 README.md\n"
     ]
    }
   ],
   "source": [
    "# commit \n",
    "! git commit -m'add_01'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "commit 1eff00ea59ffeaa6a8f7588eb69c1affcac2910c\n",
      "Author: stuvincent <stuvincent@163.com>\n",
      "Date:   Mon Oct 26 17:09:05 2020 +0800\n",
      "\n",
      "    'add_01'\n"
     ]
    }
   ],
   "source": [
    "! git log"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[master f3382c7] 'add_01-rename'\n",
      " Date: Mon Oct 26 17:09:05 2020 +0800\n",
      " 2 files changed, 40 insertions(+)\n",
      " create mode 100644 .gitignore\n",
      " create mode 100644 README.md\n"
     ]
    }
   ],
   "source": [
    "# commit 更新标注信息\n",
    "! git commit --amend -m'add_01-rename'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "commit f3382c7bc6371d0c1ec92b45a83ab8eda94122c3\n",
      "Author: stuvincent <stuvincent@163.com>\n",
      "Date:   Mon Oct 26 17:09:05 2020 +0800\n",
      "\n",
      "    'add_01-rename'\n"
     ]
    }
   ],
   "source": [
    "! git log"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 创建新分支\n",
    "! git branch Branch_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Branch_1\n",
      "* master\n"
     ]
    }
   ],
   "source": [
    "# 查看 git 分支\n",
    "! git branch "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Switched to branch 'Branch_1'\n"
     ]
    }
   ],
   "source": [
    "# 切换分支\n",
    "! git checkout Branch_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 新增 文件\n",
    "! touch Branch_1.txt\n",
    "! echo Branch_1 demo >> Branch_1.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "On branch Branch_1\n",
      "Untracked files:\n",
      "  (use \"git add <file>...\" to include in what will be committed)\n",
      "\n",
      "\tBranch_1.txt\n",
      "\n",
      "nothing added to commit but untracked files present (use \"git add\" to track)\n"
     ]
    }
   ],
   "source": [
    "# 查看 git 状态\n",
    "! git status "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "! git diff Branch_1.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "! git add ."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Branch_1 4c7e438] 'Branch_1-commit'\n",
      " 1 file changed, 1 insertion(+)\n",
      " create mode 100644 Branch_1.txt\n"
     ]
    }
   ],
   "source": [
    "! git commit -m 'Branch_1-commit'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "commit 4c7e438fe3dec2e625704d99174ecdf12fbd307a\n",
      "Author: stuvincent <stuvincent@163.com>\n",
      "Date:   Mon Oct 26 17:09:12 2020 +0800\n",
      "\n",
      "    'Branch_1-commit'\n",
      "\n",
      "commit f3382c7bc6371d0c1ec92b45a83ab8eda94122c3\n",
      "Author: stuvincent <stuvincent@163.com>\n",
      "Date:   Mon Oct 26 17:09:05 2020 +0800\n",
      "\n",
      "    'add_01-rename'\n"
     ]
    }
   ],
   "source": [
    "! git log"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Switched to branch 'master'\n"
     ]
    }
   ],
   "source": [
    "# 换回 master\n",
    "! git checkout master"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "commit f3382c7bc6371d0c1ec92b45a83ab8eda94122c3\n",
      "Author: stuvincent <stuvincent@163.com>\n",
      "Date:   Mon Oct 26 17:09:05 2020 +0800\n",
      "\n",
      "    'add_01-rename'\n"
     ]
    }
   ],
   "source": [
    "! git log"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Updating f3382c7..4c7e438\n",
      "Fast-forward\n",
      " Branch_1.txt | 1 +\n",
      " 1 file changed, 1 insertion(+)\n",
      " create mode 100644 Branch_1.txt\n"
     ]
    }
   ],
   "source": [
    "# 将 Branch_1 分支合并到 master 分支中\n",
    "! git merge Branch_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "commit 4c7e438fe3dec2e625704d99174ecdf12fbd307a\n",
      "Author: stuvincent <stuvincent@163.com>\n",
      "Date:   Mon Oct 26 17:09:12 2020 +0800\n",
      "\n",
      "    'Branch_1-commit'\n",
      "\n",
      "commit f3382c7bc6371d0c1ec92b45a83ab8eda94122c3\n",
      "Author: stuvincent <stuvincent@163.com>\n",
      "Date:   Mon Oct 26 17:09:05 2020 +0800\n",
      "\n",
      "    'add_01-rename'\n"
     ]
    }
   ],
   "source": [
    "! git log"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Switched to branch 'Branch_2'\n"
     ]
    }
   ],
   "source": [
    "# 创建新分支\n",
    "! git branch Branch_2\n",
    "# 切换分支\n",
    "! git checkout Branch_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Branch_2 分支  新增 文件\n",
    "! touch Branch_2.txt\n",
    "! echo Branch_2 demo >> Branch_2.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "On branch Branch_2\n",
      "Untracked files:\n",
      "  (use \"git add <file>...\" to include in what will be committed)\n",
      "\n",
      "\tBranch_2.txt\n",
      "\n",
      "nothing added to commit but untracked files present (use \"git add\" to track)\n",
      "[Branch_2 6853074] 'Branch_2-commit'\n",
      " 1 file changed, 1 insertion(+)\n",
      " create mode 100644 Branch_2.txt\n"
     ]
    }
   ],
   "source": [
    "# 查看 git 状态\n",
    "! git status \n",
    "! git add .\n",
    "! git commit -m 'Branch_2-commit'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Switched to branch 'master'\n"
     ]
    }
   ],
   "source": [
    "# 换回 master\n",
    "! git checkout master"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "! echo master demo >> Branch_1.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Updating 4c7e438..6853074\n",
      "Fast-forward\n",
      " Branch_2.txt | 1 +\n",
      " 1 file changed, 1 insertion(+)\n",
      " create mode 100644 Branch_2.txt\n"
     ]
    }
   ],
   "source": [
    "# 将 Branch_2 分支合并到 master 分支中\n",
    "! git merge Branch_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "On branch master\n",
      "Changes not staged for commit:\n",
      "  (use \"git add <file>...\" to update what will be committed)\n",
      "  (use \"git checkout -- <file>...\" to discard changes in working directory)\n",
      "\n",
      "\tmodified:   Branch_1.txt\n",
      "\n",
      "no changes added to commit (use \"git add\" and/or \"git commit -a\")\n"
     ]
    }
   ],
   "source": [
    "! git status"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
